package solver

type Strategy func() bool

func (g *Grid) prepareStrategies() {
	if g.strategies != nil && len(g.strategies) != 0 {
		return
	}

	g.strategies = []Strategy{
		g.LastOne,
		g.HiddenSingleBoxes,
		g.HiddenSingleRows,
		g.HiddenSingleCols,
		g.NakedSingle,
		g.Pointing,
		g.Claiming,
		g.HiddenPair,
		g.NakedPair,
		g.HiddenTriple,
		g.NakedTriple,
		g.HiddenQuandruple,
		g.NakedQuadruple,
		g.XWing,
		g.Swordfish,
		g.Jellyfish,
		g.XYWing,
		g.XYZWing,
		g.Skycraper,
		g.TwoStringKite,
		g.TurbotFish,
		g.WWing,
	}
}

func (g *Grid) Solve() {
	if g.strategies == nil || len(g.strategies) == 0 {
		g.prepareStrategies()
	}
	used := false
	for {
		for _, strategy := range g.strategies {
			used = strategy()
			if used {
				break
			}
		}

		if !used {
			break
		}
		used = false
	}
}
